// packagMy/pages/partnerOrder/partnerOrder.js
var configUrl = require('../../../config/config')  //引入配置接口文件
const app=getApp();
const comUrl=app.globalData.comUrl
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    page:1,
    row:15,
    parms:{},
    notMovePage:false,
    orderList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff'
    })
    wx.setNavigationBarTitle({
      title: '我的分销订单',
    })
  },
  onChange(event) {  //切换订单状态
    this.setData({
      active:event.detail.index,
      parms:{},
      page:1,
      notMovePage:false,
      orderList:[]
    })
    this.getOrderList(event.detail.index)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getOrderList()
  },
  getOrderList(type){
    var that=this
    //子订单状态   0待付款  1已取消    2待发货    3部分发货    4待收货    5已关闭   6交易成功
    var parms=this.data.parms
    parms.page = that.data.page
    parms.rows = that.data.row
    if(type==1){  //已付款
      var status=['2','3','4','6']
      parms.paramsRaw=JSON.stringify({status:status})
    }else if(type==2){   //待支付
      var status=['0']
      parms.paramsRaw=JSON.stringify({status:status})
    }else if(type==3){   //已失效
      var status=['1','5']
      parms.paramsRaw=JSON.stringify({status:status})
    }
    var userId=wx.getStorageSync('loginMsg').userId
    app.reqFun.requestForm('POST',configUrl.distributionOrder+userId,parms,(res)=>{
      if(res.data.success==1){
        let orlist = res.data.data.records
        if(orlist.length < that.data.row && orlist.length != 0){
          that.setData({
            notMovePage:true
          })
        }
        that.setData({
          orderList: that.data.orderList.concat(orlist),
          parms:parms
        })
      }
    })
  },
  partnerOrderDetail(data) {
    let orderId = data.currentTarget.dataset.data.orderId
    let parentId = data.currentTarget.dataset.parentid
    console.log('data', data)
    let option = {
      parentId: parentId,
      orderId: orderId
    }
    wx.navigateTo({
      url: '../partnerOrderDetail/partnerOrderDetail?option=' + JSON.stringify(option)
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(!this.data.notMovePage){
      var parms=this.data.parms 
      this.setData({
        parms:parms,
        page: this.data.page + 1
      })
      var type=this.data.active
      this.getOrderList(type)
    }
    
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})